package com.zjf.addresschk;

import com.zjf.addresschk.entity.AddressEntity;
import com.zjf.addresschk.entity.InfBaidu;
import com.zjf.addresschk.entity.InfGoogle;
import com.zjf.addresschk.service.AddressChkService;
import com.zjf.addresschk.service.AddressChkServiceBaidu;
import com.zjf.addresschk.service.AddressChkServiceGoogle;

import java.util.List;

/**
 * 地址检测工具
 */
public class App 
{
    public static void main( String[] args )
    {

        //谷歌接口(适用于国外地址,国内也可以用)
        executeGoogle(AppProperties.inPath, AppProperties.outPath);
        //百度接口（适用于查询国内地址）
//        executeBaidu(AppProperties.inPath, AppProperties.outPath);
    }

    public static void executeGoogle(String inPath, String outPath) {
        /*
         *谷歌接口
         */
        AddressChkService service = new AddressChkServiceGoogle(new InfGoogle(AppProperties.apiKey_google));
        executeService(inPath, outPath, service);
    }


    public static void executeBaidu(String inPath, String outPath){
         /*
        百度地图接口
         */
//        String ak="XtBOCfgETHRj62T7TM6EDZFA";//百度地图ak
//        String sk="TUoG9a5mIU7Ktxp8nTQWWOOqCbALd1is";//百度地图sk
//        String interfaceUrl="http://api.map.baidu.com/geocoder/v2/?address={address}&output=json&ak="+ak ;//接口地址
        //调用地址 http://api.map.baidu.com/geocoder/v2/?address=深圳华南城&output=json&ak=XtBOCfgETHRj62T7TM6EDZFA&sn=e1b084959fd2cb566234341143921426
        AddressChkService service = new AddressChkServiceBaidu(new InfBaidu(AppProperties.apiKey_baidu_ak,AppProperties.apiKey_baidu_sk,AppProperties.apiKey_baidu_interfaceUrl));
        executeService(inPath, outPath, service);
    }

    public static void executeService(String inPath, String outPath, AddressChkService service) {
        //获取待检测的地址
        List<AddressEntity> addressList =  service.getAddressStr(inPath);
        //进行检测
        service.checkAddress(addressList);
        //抓取邮编
        service.catchPostcode(addressList);
        //输出结果到excel
        service.outputResult(addressList, outPath);
    }
}
